import { createFromIconfontCN, LinkOutlined } from '@ant-design/icons';
import { DefaultFooter } from '@ant-design/pro-layout';
import { Space } from "antd";

const IconFont = createFromIconfontCN({
  scriptUrl: ['//at.alicdn.com/t/font_2171248_tekhmru6ev.js', './icon-icp.js'],
});

const useBeiAn = () => {
  const data: any[] = [
    {
      domain: 'houkunlin.cn',
      domainText: 'houkunlin.cn',
      no: '45032602000032',
      text: '桂公网安备 45032602000032号',
      icpNo: '桂ICP备20000103号-1',
    },
    {
      domain: '侯坤林.我爱你',
      domainText: '侯坤林.我爱你',
      no: '45032602000036',
      text: '桂公网安备 45032602000036号',
      icpNo: '桂ICP备20000103号-2',
    },
    {
      domain: 'xn--gtqt1qqto.xn--6qq986b3xl',
      domainText: '侯坤林.我爱你',
      no: '45032602000036',
      text: '桂公网安备 45032602000036号',
      icpNo: '桂ICP备20000103号-2',
    },
    {
      domain: 'houkunlin.com',
      domainText: 'houkunlin.com',
      no: '45032602000035',
      text: '桂公网安备 45032602000035号',
      icpNo: '桂ICP备20000103号-3',
    },
    {
      domain: 'houkunlin.com.cn',
      domainText: 'houkunlin.com.cn',
      no: '45032602000034',
      text: '桂公网安备 45032602000034号',
      icpNo: '桂ICP备20000103号-4',
    },
  ];
  return data.find(item => window.location.hostname.endsWith(item.domain)) || data[0];
}

const BeiAnGongAn = () => (
  <img
    src="/beian/police_badge_64.svg"
    alt="公安备案"
    className={'anticon'}
    style={{ width: '1em', height: '1em' }}
  />
);

const BeiAn = () => {
  const beiAn = useBeiAn();

  return (
    <div style={{ textAlign: 'center', marginBottom: '20px' }}>
      <Space>
        <a href={'https://beian.miit.gov.cn'} target={'_blank'}><IconFont type="icon-ICP-LOGO" /> {beiAn.icpNo}</a>
        <a href={`https://www.beian.gov.cn/portal/registerSystemInfo?recordcode=${beiAn.no}`} target={'_blank'}>
          <BeiAnGongAn /> {beiAn.text}
        </a>
      </Space>
    </div>
  )
}

export default () => {
  const beiAn = useBeiAn();

  return (
    <>
      <DefaultFooter
        copyright={`${beiAn.domainText} ${new Date().getFullYear()} 十二后花园 版权所有`}
        links={[
          {
            key: 'houkunlin.cn',
            title: (
              <>
                <LinkOutlined /> CN.
              </>
            ),
            href: 'http://houkunlin.cn',
            blankTarget: true,
          },
          {
            key: 'houkunlin.com',
            title: (
              <>
                <LinkOutlined /> COM.
              </>
            ),
            href: 'http://houkunlin.com',
            blankTarget: true,
          },
          {
            key: 'houkunlin.com.cn',
            title: (
              <>
                <LinkOutlined /> COM.CN.
              </>
            ),
            href: 'http://houkunlin.com.cn',
            blankTarget: true,
          },
          {
            key: '侯坤林.我爱你',
            title: (
              <>
                <LinkOutlined /> 我爱你.
              </>
            ),
            href: 'http://侯坤林.我爱你',
            blankTarget: true,
          },
        ]}
      />
      <BeiAn />
    </>
  )
};
